<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateChatRecordTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('chat_record', ['comment' => '聊天记录', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('chat_user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '顾客'])
            ->addColumn('room_id', 'string', ['limit' => 60, 'default' => 'admin', 'comment' => '房间号'])
            ->addColumn(Column::enum('sender_identify', ['customer_service', 'customer'])->setDefault('customer')->setComment('发送身份'))
            ->addColumn('sender_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '发送者'])
            ->addColumn(Column::enum('message_type', ['text', 'image', 'file', 'system', 'goods', 'order'])->setDefault('text')->setComment('消息类型'))
            ->addColumn('message', 'text', ['null' => true, 'default' => null, 'comment' => '消息'])
            ->addColumn('read_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '读取时间'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('chat_user_id')
            ->addIndex(['sender_identify', 'sender_id'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('chat_record');
        $table->drop();
    }
}
